package com.soft.sitegenerator;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.soft.sitegenerator.Component;

public class DataBaseComponent implements Component {

    private static BeanFactory beanFactory;

           private void loadBeans() {
               System.out.println("Looking up for environment");
               String[] beans = new String[]{"/databaseBeans.xml"};
               beanFactory = new ClassPathXmlApplicationContext(beans);
           }


           public synchronized Object getObject(String className) {
               if (beanFactory == null)
                   loadBeans();
               return beanFactory.getBean(className);
           }


           public ApplicationContext getApplicationContext() {
               return (ApplicationContext) beanFactory;
           }


           public BeanFactory getBeanFactory() {
               return beanFactory;
           }


           public Object getBean(String className) {
               return getObject(className);
           }
}
